#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

bool myComp(const char *lhs, const char *rhs)
{
    return *lhs < *rhs;
}

string largetsSuffixBruteForce(const string &str)
{
    const char *p = str.c_str();
    vector<const char *> strVec;
    for (int i = 0; i < str.size(); i++) {
        strVec.push_back(p+i);
    }    
    sort(strVec.begin(), strVec.end(), myComp);
    for (int i = 0; i < strVec.size(); i++) 
        cout << strVec[i] << endl;
    return strVec[strVec.size()-1];
}

string largetsSuffix(const string &str)
{
    char *p = (char*)str.c_str();
    char *ans = p+str.size();
    vector<const char *> strVec;
    for (int i = str.size()-1; i >= 0; i--) {
        if (*ans < *(p+i)) ans = p+i;
    }    
    return ans;
}

int main(int argc, char **argv)
{
    string str = "njkadfkjnwenknknwekvuoiwkjenkwn";
    cout << largetsSuffixBruteForce(str) << endl;    
    cout << largetsSuffix(str) << endl;    


}
